package tools;

import java.util.HashMap;
import java.util.Vector;

import javax.swing.table.DefaultTableModel;

import domain.Student;

public class FileHash {
	private static Vector<Student> Data=FileTool.getData();//从文件中拿数据
	private static HashMap<String, Vector<Student>>mp1=new HashMap<>();//哈希表1 id和学生信息对应
	private static HashMap<String, Vector<Student>>mp2=new HashMap<>();//哈希表2 课程和表信息对应
	static {
		for(int i=0;i<Data.size();i++) {
			//筛选同样的ID
			Vector<Student> list=new Vector<>();
			Student s=Data.get(i);
			String id=s.getID();
			if(mp1.containsKey(id)) {
				continue;
			}		
			for(int j=i;j<Data.size();j++) {
				s=Data.get(j);
				if(s.getID().equals(id)) {
					list.add(s);
				}							
			}
			mp1.put(id,list);
		}			
		for(int i=0;i<Data.size();i++) {
			//筛选同样的课程
			Vector<Student> list=new Vector<>();
			Student s=Data.get(i);
			String course=s.getCourse();
			if(mp2.containsKey(course)) {
				continue;
			}		
			for(int j=i;j<Data.size();j++) {
				s=Data.get(j);
				if(s.getCourse().equals(course)) {
					list.add(s);
				}							
			}
			mp2.put(course,list);
		}	
	}	
	public static HashMap<String,Vector<Student>> getMap(){
		return mp1;
	}
	public static HashMap<String,Vector<Student>> getMap2(){
		return mp2;
	}
}
